package com.example.demo.rabbitmq;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component

public class Receiver {
    @RabbitHandler
    @RabbitListener(queues = "order-queue")
    public void receiver( @Payload Object obj,@Headers Map<String,Object> head, Channel channel) throws IOException {
        System.out.println("消费开始" + obj);
        long delivery = (Long)head.get(AmqpHeaders.DELIVERY_TAG);
        channel.basicAck(delivery,false);
    }
//    @RabbitHandler
//    public void process(String hello){
//        System.out.println("Receiver:----------" + hello);
//    }

}
